<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="报告人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reporter">
              <a-input readOnly v-model="model.reporter" placeholder="请输入报告人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <!-- 
              <j-date placeholder="请选择报告日期" v-model="model.reportDate"  style="width: 100%" />
             -->
            <a-form-model-item label="报告日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportDate">
              <a-input readOnly v-model="model.reportDate" placeholder="请选择报告日期"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作目标和任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workObjectivesAndTasks">
              <a-textarea v-model="model.workObjectivesAndTasks" rows="4" placeholder="请输入工作目标和任务" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本周任务完成情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="completStatusTasks">
              <a-textarea v-model="model.completStatusTasks" rows="4" placeholder="请输入本周任务完成情况" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下周工作计划" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nextWeekWorkPlan">
              <a-textarea v-model="model.nextWeekWorkPlan" rows="4" placeholder="请输入下周工作计划" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="问题或建议" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="questionsOrSuggest">
              <a-textarea v-model="model.questionsOrSuggest" rows="4" placeholder="请输入问题或建议" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="领导评价与反馈" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leaderEvaluate">
              <a-textarea v-model="model.leaderEvaluate" rows="4" placeholder="请输入领导评价与反馈" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ZbsWorkWeekReportForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        model: {
        reporter: localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')).realname : '',
        reportDate : ''
      },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/zbsWorkWeekReport/add",
          edit: "/ch/zbsWorkWeekReport/edit",
          queryById: "/ch/zbsWorkWeekReport/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      // 计算时间
      var date = new Date()
      var year = date.getFullYear()
      var month = date.getMonth() < 10 ? '0' + (date.getMonth() +1) : date.getMonth()+1
      var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      this.model.reportDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + second
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));

    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>